//--------------------------------------------------------------------
// Pseudo Source Code of CADJPYM60StopLongStrategy 9.84.82_250908011
//
//   Generated by StrategyQuant X Build 143 for MetaTrader5 (hedged)
//   at 02/06/2026 11:14
//
//   Backtested on CADJPY_darwinex / H1, 2019.01.02 - 2026.01.30
//   Backtest engine: MetaTrader5 (hedged)
//--------------------------------------------------------------------


//--------------------------------------------------------------------
//  Strategy Parameters
//--------------------------------------------------------------------
int MagicNumber = 11111;
int Period1 = 20;
int Period2 = 45;
int Period3 = 50;
int ExitAfterBars1 = 26;
double MoveSL2BECoef1 = 2.9;
double SL2BEAddPips1 = 2.1;
double ProfitTargetCoef1 = 4.2;
double StopLossCoef1 = 2.8;

Main chart = Current Symbol / Current TF;

//--------------------------------------------------------------------
// Trading options logic
//--------------------------------------------------------------------

Don't Trade On Weekends = false (Friday 0038 - Sunday 0038);
Exit at End Of Day = false (2304);
Exit On Friday = true (2000);
LimitSignalsTimeRange = true (0200 - 2200, Exit at End: true, Orders to close: Pending only);
LimitMaxDistanceFromMarketPrice = false;   //Limit max distance
MaxDistanceFromMarketPct = 6;   //Max distance %
MaxTradesPerDay = 0;
Min SL: 20, Max SL: 0, Min PT: 20, Max PT: 0; // in ticks/pips, 0 means unlimited

// Template for a trading option LimitOver missing, ignoring!


//--------------------------------------------------------------------
// Trading rule: Trading signals (On Bar Open)
//--------------------------------------------------------------------           
LongEntrySignal = ((((Lowest(Main chart, Period1, PRICE_LOW)[1] < CloseWeekly(Main chart)[1])
   and (Lowest(Main chart, Period2, PRICE_HIGH)[1] < HeikenAshiClose(Main chart)[1]))
   and (Lowest(Main chart, Period3, PRICE_LOW)[1] < CloseWeekly(Main chart)[1]))
   and (Lowest(Main chart, Period3, PRICE_HIGH)[1] < CloseWeekly(Main chart)[1]));

ShortEntrySignal = false;

LongExitSignal = false;

ShortExitSignal = false;


//--------------------------------------------------------------------
// Trading rule: Long entry (On Bar Open)
//--------------------------------------------------------------------           
if LongEntrySignal
{
    // Action #1
    Open Long order at SessionHigh(22:7-2:8)[1] Stop;
        Order valid for 47 bars;
		Size = according to Global MM;
		Comment = "";
		Duplicate trades = disabled;
		Replacing pending orders: allowed; 

        Stop Loss = StopLossCoef1 * ATR(30);
        Profit target = ProfitTargetCoef1 * ATR(45);

        Move SL to BE = MoveSL2BECoef1 * ATR(8), add SL2BEAddPips1 pips pips to BE;

        Exit After ExitAfterBars1 bars;
}

//--------------------------------------------------------------------
// Trading rule: Short entry (On Bar Open)
//--------------------------------------------------------------------           
if (ShortEntrySignal
   and Not LongEntrySignal)
{
}

//--------------------------------------------------------------------
// Trading rule: Long exit (On Bar Open)
//--------------------------------------------------------------------           
if ((LongExitSignal
   and Not LongEntrySignal)
   and (MarketPosition("Any", MagicNumber, "") is Long))
{
    // Action #1
    Close all positions for Symbol = Any and Magic Number = MagicNumber;

}

//--------------------------------------------------------------------
// Trading rule: Short exit (On Bar Open)
//--------------------------------------------------------------------           
if ((ShortExitSignal
   and Not ShortEntrySignal)
   and (MarketPosition("Any", MagicNumber, "") is Short))
{
    // Action #1
    Close all positions for Symbol = Any and Magic Number = MagicNumber;

}



Broker: No filter
